package com.nb.controller;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        //原数组
        String a[] = {"sss", "island", "ocean"};
        Scanner sc = new Scanner(System.in);
        System.out.print("输入新歌曲：");
        String next = sc.next();
        //新数组
        String b[] = new String[a.length + 1];

        int index = -1;
        System.out.print("排序前的歌曲：");
        for (int i = 0; i < a.length ; i++) {
            if ((i+1)<a.length){
                if (a[i].compareToIgnoreCase(a[i + 1]) > 0) {
                    index = i;
                }
                String temp = a[index];
                a[index] = a[index + 1];
                a[index + 1] = temp;
            }
            System.out.print(a[i] + "   ");
        }

        //复制
        for (int i = 0; i < a.length; i++) {
            b[i] = a[i];
        }
        System.out.println();
        //插入判断
        System.out.print("排序后的歌曲：");
        for (int i = 0; i<b.length-1;i++){
            if ((i+1)<b.length){
                if (next.compareToIgnoreCase(b[i])<0){
                    index = i;
                }
                String temp = b[index];
                String temp2 = b[index+1];
                //保存
                b[index] = next;
                b[index+1] = temp;
                b[b.length-1] = temp2;
                for (int j = 0; j < b.length; j++) {
                    System.out.print(b[j]+"    ");

                }
                System.out.println();
                System.out.println();
                System.out.println();
            }
        }


    }
}
